import axios from 'axios'

// 创建axios实例
const http = axios.create({
  baseURL: "http://localhost:8080",
  timeout: 10000
})

// 请求拦截器
http.interceptors.request.use(config => {
  const token = localStorage.getItem('token')
  if (token) {
    config.headers.Authorization = `Bearer ${token}`
  }
  return config
})

// 响应拦截器
http.interceptors.response.use(
  response => response.data,
  error => {
    console.error('请求失败', error)
    return Promise.reject(error)
  }
)

export default http